package week4.num.ExceptionDemo01.neuedu2.demo01;

import com.neueduTotal.solar.Constant;
import com.neueduTotal.solar.imageUtil;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class JFrameTest extends Frame {

    Image sun= imageUtil.getImage("太阳.png");
    int weight=sun.getWidth(null);
    int height=sun.getHeight(null);
    Image bg=imageUtil.getImage("background.png");


    public void loadFrame() {

        this.setSize(Constant.WINDOw_WIDTH, Constant.WINDOw_HEIGHT);
        //调整位置水平居中
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setResizable(false);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        this.setTitle("太阳系八大行星轨道运行系统");
        this.setIconImage(sun);
    }

    @Override
    public void paint(Graphics g) {
        g.drawImage(bg,0,0,null);
        g.drawImage(sun,Constant.WINDOw_WIDTH/2-weight/2,Constant.WINDOw_HEIGHT/2-height/2,null);
    }

    public static void main(String[] args) {
        new JFrameTest().loadFrame();
    }

}
